package com.linkstec.controller;

import java.util.List;

import jakarta.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.linkstec.pojo.User;
import com.linkstec.service.UserServiceImpl;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;


@RestController
@Tag(name = "用户管理")
public class UserController {

	@Resource
	private ApplicationContext ctx;
    @Autowired
    private UserServiceImpl userService;
    @Autowired
    private User user;
    //显示用户
    @GetMapping("list")
    @Operation(summary = "用户列表", description = "查询列表notes")
    public List<User> index() throws Exception {
    	List<User> user = userService.getUser();
        return user;
    }
    //删除用户
    @Operation(summary = "删除用户", description = "删除用户notes")
    @GetMapping("delete/{id}")
    public String delete(@PathVariable int id) throws Exception {
        userService.deleteUser(id);
        return "你已经删掉了id为"+id+"的用户";
    }
    //增加用户
    @PostMapping("addUser")
    @Operation(summary = "添加用户", description = "添加用户notes")
    public String addUser(Long id) throws Exception {
        user.setId(id);
        user.setAge(33);
        user.setUsername("阿花");
        userService.addUser(user);
        return "增加用户";
    }
    //获取上下文对象
    @RequestMapping("ctx")
    public void ctx() throws Exception {
    	System.out.println("===========================================");
    	//获取字符串
    	System.out.println("String: " + (ctx.getEnvironment().getProperty("com.demo.name") + 1111) );
    }

}